package com.itheima.web;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.pojo.Result;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 29143
 */
@RestController
@RequestMapping("/user")
public class UserWeb {

    @Autowired
    private UserService userService;

    /**
     * 根据id查询查询用户
     * @param uid
     * @return
     */
    @GetMapping("/{uid}")
    public Result findUserById(@PathVariable("uid") Integer uid){
        return userService.findUserById(uid);
//        return userService.findUserById(uid);
    }

    /**
     * 查询所有用户信息
     * @return
     */
    @GetMapping("/all")
    public Result findAll (){
        return userService.findAll();
//        return userService.findAll();
    }

    @GetMapping("/findByPage/{page}/{size}")
    public Result findUserByPage(@PathVariable("page") Integer page,
                                      @PathVariable("size") Integer size){
        return userService.findUserByPage(page,size);
    }

    /**
     * 添加用户对象
     * @param user
     * @return
     */
    @PostMapping("/addUser")
    public Result addUser(@RequestBody User user){
        return userService.addUser(user);
//        return userService.addUser(user);
    }

    /**
     * 修改用户信息
     * @param user
     * @return
     */
    @PutMapping("/updateUser")
    public Result updateUser(@RequestBody User user){
        return userService.updateUser(user);
//        return userService.updateUser(user);
    }

    /**
     * 根据id删除用户
     * @param uid
     * @return
     */
    @DeleteMapping("/delete/{uid}")
    public Result deleteUser(@PathVariable("uid") Integer uid){
        return userService.deleteUserByUid(uid);
//        return userService.deleteUserByUid(uid);
    }




}
